(ns first-clojure.middleware.interceptor
  (:require
    [clj-jwt.core  :refer :all]
    [clj-jwt.key   :refer [private-key]]
    [clj-time.core :refer [now plus days]]))

;; jwt: https://github.com/liquidz/clj-jwt
(def claim
  {:iss "user"
   :exp (plus (now) (days 1))
   :iat (now)})

(defn custom-wrap [handler]
  (fn [request]
    ;(println request)
    (println "处理request之前")
    (println (str "token:" (-> claim jwt to-str)))
    (let [respond (handler request)]
      ;; 从request里拿到需要的字段，设备Device，用户token之类，需要输出或者判断的放在这里
      ;; verify plain JWT
      (let [token (-> claim jwt to-str)]
        (println (str "token校验：" (-> token str->jwt verify))))
      (println "处理request之后")
      respond)))